package solution;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-01-21
 * Time: 17:25
 */

//https://leetcode.cn/problems/day-of-the-year/submissions/396579406/
    //
class Solution4 {
    public static void main(String[] args) {
        String data = "2012-01-02";
        dayOfYear(data);
    }
    public static int dayOfYear(String date) {
        int year = Integer.parseInt(date.substring(0, 4));
        int month = Integer.parseInt(date.substring(5, 7));
        int day = Integer.parseInt(date.substring(8));
        int[] months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        int days = 0;
        days += day;
        //教训：布尔表达式该使用()的不可省略
        //如第一个&&后的()!!!!!
        if (month > 2 && (year % 400 == 0 || year % 100 != 0 && year % 4 == 0)) {
            days++;
        }
        for (int i = 0; i < month - 1; i++) {
            days += months[i];
        }
        return days;
    }
}
